<!--
Copyright 2018 Google LLC. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================
-->

<!doctype html>

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="../shared/tfjs-examples.css" />
</head>

<style>
  #load-model-div {
    margin-top: 10px;
    margin-bottom: 10px;
  }

  #reset {
    margin-left: 100px;
  }

  #show-q-values-div {
    margin-top: 5px;
  }

  #game-status-div {
    margin-top: 15px;
  }
</style>

<body>
  <div class='tfjs-example-container centered-container'>
    <section class='title-area'>
      <h1>TensorFlow.js Reinforcement Learning: Snake DQN</h1>
      <p class='subtitle'>Deep Q-Network for the Snake Game</p>
    </section>
    <section>
      <p class='section-head'>Description</p>
      <p>
        This page loads a trained Deep Q-Network (DQN) and use it to play the
        snake game.
        The training is done in Node.js using <a href="https://github.com/tensorflow/tfjs-node">tfjs-node</a>.
        See <a href="https://github.com/tensorflow/tfjs-examples/blob/master/snake-dqn/train.js">train.js</a>.
      </p>
    </section>
    <section>
      <p class='section-head'>Algorithm</p>
      <p>
        A <a href="https://en.wikipedia.org/wiki/Q-learning#Variants">DQN</a> is trained to estimate the value of actions given the current game state.
        The DQN is a 2D convolutional network. See <a href="https://github.com/tensorflow/tfjs-examples/blob/master/snake-dqn/dqn.js">dqn.js</a>.
        The epsilon-greedy algorithm is used to balance exploration and exploitation during training.
      </p>
    </section>

    <section>
      <div id="load-model-div">
        <button id="load-hosted-model" width="200px" disabled>Load hosted model</button>
      </div>

      <div>
        <button id="auto-play-stop" disabled>Auto Play</button>
        <button id="step" disabled>Step</button>
        <button id="reset" disabled>Reset</button>
      </div>
      <div id="show-q-values-div">
        <input type="checkbox" id="show-q-values" checked>
        <span>Show Q-values</span>
      </div>
      <div id="game-status-div">
        <span id="game-status">Game started.</span>
      </div>
      <div>
        <canvas id="game-canvas" height="400px" width="400px"></canvas>
      </div>
    </section>

  </div>

</body>

<script src="index.js"></script>
